//
//  TabViewController.m
//  AGG_V2
//
//  Created by admin on 15/5/9.
//  Copyright (c) 2015年 admin. All rights reserved.
//

#import "AGGTabViewController.h"
#import "AGGNavigationController.h"
#import "UINavigationController+FDFullscreenPopGesture.h"
#import "INTULocationManager.h"
//#import "AFNetworkTool.h"
#import "ConversationListController.h"
#import "ContactListViewController.h"


//#import "HNServiceViewController.h"
#import "ConversationListController.h"
#import "HNQAViewController.h"
#import "HNFamousDoctorController.h"
#import "HNPatientViewController.h"
#import "HNMyViewController.h"
@interface AGGTabViewController ()<UITabBarControllerDelegate,UIAlertViewDelegate,MKMapViewDelegate,CLLocationManagerDelegate>
{
    AGGNavigationController *sectionOne;
    AGGNavigationController *sectionTwo;
    AGGNavigationController *sectionThree;
    AGGNavigationController *sectionFour;
    AGGNavigationController *sectionFive;
    CLLocationManager *_locationManager;
    CLLocationCoordinate2D _currentLocationCoordinate;
}
@property (nonatomic, strong) UIButton *centerButton;

@end

@implementation AGGTabViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

/**
 *  第一次调用类的时候会调用该方法
 */
+ (void)initialize {
    //设置UITabBarItem的主题
    [self setupTabBarItemTheme];
}

/**
 *  设置UITabBarItem的主题
 */
+ (void)setupTabBarItemTheme {
    //通过设置 appearance对象，能够修改整个项目中所有UITabBarItem的样式
    UITabBarItem *appearance = [UITabBarItem appearance];
    
    //Normal
    [appearance
     setTitleTextAttributes:[NSDictionary
                             dictionaryWithObjects:[NSArray arrayWithObjects:[UIColor colorWithHexString:@"#707070"],
                                                    [UIFont systemFontOfSize:11.0f], nil]
                             forKeys:[NSArray arrayWithObjects:NSForegroundColorAttributeName, NSFontAttributeName, nil]]
     forState:UIControlStateNormal];
    
    //Selected
    [appearance
     setTitleTextAttributes:[NSDictionary
                             dictionaryWithObjects:[NSArray arrayWithObjects:[UIColor colorWithHexString:@"#707070"],
                                                    [UIFont systemFontOfSize:11.0f], nil]
                             forKeys:[NSArray arrayWithObjects:NSForegroundColorAttributeName, NSFontAttributeName, nil]]
     forState:UIControlStateSelected];
    
    UITabBar *barApperance = [UITabBar appearance];
    [barApperance setBarTintColor:[UIColor whiteColor]];
}

//-(void)startLocation{
//    INTULocationManager *locMgr = [INTULocationManager sharedInstance];
//    [locMgr requestLocationWithDesiredAccuracy:INTULocationAccuracyCity
//                                       timeout:10.0
//                          delayUntilAuthorized:YES  // This parameter is optional, defaults to NO if omitted
//                                         block:^(CLLocation *currentLocation, INTULocationAccuracy achievedAccuracy, INTULocationStatus status) {
//                                             if (status == INTULocationStatusSuccess) {
//                                                 NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%f",currentLocation.coordinate.longitude], @"userPrecision",[NSString stringWithFormat:@"%f",currentLocation.coordinate.latitude], @"userLatitude",USERDEFAULTS.userModel.userId,@"userId",nil];
//                                                 [AFNetworkTool NetWorkRequest:@"mobile/user/userPlace" parameters:param WithSuceessMessage:nil WithMethod:@"updateLocationSuccess" WithController:self AndInfoView:self.view];
//                                                 [USER_DEFAULT setObject:[NSString stringWithFormat:@"%f",currentLocation.coordinate.longitude] forKey:XXBUserPrecisions];
//                                                 [USER_DEFAULT setObject:[NSString stringWithFormat:@"%f",currentLocation.coordinate.latitude] forKey:XXBUserLatitudes];
//                                                 //定位成功
//                                                 NSLog(@"latitude = %f longitude = %f",currentLocation.coordinate.latitude,currentLocation.coordinate.longitude);
//                                             }
//                                             else if (status == INTULocationStatusTimedOut) {
//                                                 //超时
//                                                 NSLog(@"超时");
//                                             }
//                                             else {
//                                                 //错误
//                                                 NSLog(@"错误");
//                                             }
//                                         }];
//}

//上传位置成功
-(void)updateLocationSuccess{
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
//    [NotificationCenter addObserver:self selector:@selector(startLocation) name:XXBLOGINSUCCESS object:nil];
//    [NotificationCenter addObserver:self selector:@selector(setRootView) name:XXBDIDLOGINFROMOTHERDEVICE object:nil];
//    if ([USERDEFAULTS isLogin]) {
//        [self startLocation];
//    }
    
    [self.navigationController.navigationBar setTitleTextAttributes:
     
     
     
     @{NSFontAttributeName:[UIFont systemFontOfSize:15],
       
    
       NSForegroundColorAttributeName:[UIColor redColor]}];
    
    [self setFd_prefersNavigationBarHidden:YES];
    [self setRootView];
}


-(void)setRootView{
    HNMyViewController *section5 = [[HNMyViewController alloc]init];
    
    HNPatientViewController *section4 = [[HNPatientViewController alloc]init];
    
    HNFamousDoctorController *section3 = [[HNFamousDoctorController alloc]init];
    
    HNQAViewController *section2 = [[HNQAViewController alloc]init];
    
//    HNServiceViewController *section1 = [[HNServiceViewController alloc]init];
    ConversationListController *section1 = [[ConversationListController alloc]init];
    
    //几个界面
    sectionOne = [[AGGNavigationController alloc] initWithRootViewController:section1];
    sectionTwo = [[AGGNavigationController alloc] initWithRootViewController:section2];
    sectionThree = [[AGGNavigationController alloc] initWithRootViewController:section3];
    sectionFour = [[AGGNavigationController alloc] initWithRootViewController:section4];
    sectionFive = [[AGGNavigationController alloc] initWithRootViewController:section5];
    
    self.viewControllers = @[sectionOne,sectionTwo,sectionThree,sectionFour,sectionFive];
    NSArray *titles = @[@"服务", @"问答", @"名医", @"患者",@"我的"];
    NSArray *images = @[@"icon_service", @"icon_QA",@"icon_QA-FamousDoctor", @"icon_QA-patient", @"icon_my"];
    [self.tabBar.items enumerateObjectsUsingBlock:^(UITabBarItem *item, NSUInteger idx, BOOL *stop) {
        [item setTitle:titles[idx]];
        [item setImage:[[UIImage imageNamed:images[idx]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        [item setSelectedImage:[[UIImage imageNamed:[images[idx] stringByAppendingString:@"-selected"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        
        //        UIViewController *section  = [arrSectionClass objectAtIndex:idx];
        //        section.navigationItem.title = [titles objectAtIndex:idx];
        
    }];
    
    self.view.backgroundColor = [UIColor whiteColor];
}

////过度动画
//- (id <UIViewControllerAnimatedTransitioning>)tabBarController:(UITabBarController *)tabBarController
//            animationControllerForTransitionFromViewController:(UIViewController *)fromVC
//                                              toViewController:(UIViewController *)toVC  NS_AVAILABLE_IOS(7_0);
//{
//
//
//    return ani;
//
//}


/**
 *  跳转其他的界面
 *
 *  @param tabBarController
 *  @param viewController
 *
 *  @return 是否登录  判断是否允许跳转
 */
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    //    if ([XXBConversationListController class] == [[viewController.childViewControllers[0] class] class] || [TocuhFriendViewController class] == [[viewController.childViewControllers[0] class] class]) {
    //    if ([SectionOneViewController class] != [[viewController.childViewControllers[0] class] class]) {
    //        if ([USERDEFAULTS isLoginAndLogin:self]) {
    //            return NO;
    //        }else{
    //            if([EMClient sharedClient].isLoggedIn){
    //                return YES;
    //            }else{
    //                EMError *error = [[EMClient sharedClient] loginWithUsername:USERDEFAULTS.userModel.userPhone password:@"111111"];
    //                if (!error) {
    //                    return YES;
    //                }else{
    //                    E(error.errorDescription);
    //                    return NO;
    //                }
    //            }
    //        }
    //    }
    return YES;
}

//-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
//    if (buttonIndex == 0) {
//        return;
//    }else{
//        NSLog(@"立即登录");
//        LoginViewController *login                                           = [[LoginViewController alloc]init];
//        [O2ONavCtl pushViewController:login animated:YES];
//        // [Util cutView:login navigationController:self.navigationController];
//    }
//}



@end




